﻿using System;

namespace ConsoleApp1
{
    class Program
    {
        //链表节点
        public class Node<T>
        {
            public Node<T> Next
            {
                get;
                set;
            }
            public T Data
            {
                get;
                set;
            }
            public Node(T t)
            {
                Next = null;
                Data = t;
            }
        }

        public class GenericList<T> {
            private Node<T> head;
            private Node<T> tail;
            public GenericList()
            {
                tail = null;
                head = null;
            }
            public Node<T> Head
            {
                get => head;
            }
            public void Add(T t)
            {
                Node<T> n = new Node<T>(t);
                if (tail == null)
                {
                    head = n;
                    tail = n;
                }
                else
                {
                    tail.Next = n;
                    tail = n;
                }
            }
            public T tem;
            public void ForEach(Action<T> action)
            {
                Node<T> i = head;
                while (i != null)
                {
                    tem = i.Data;
                    action(tem);
                    i = i.Next;
                }
            }

        }
        static void Main(string[] args)
        {

            Random t = new Random();
            GenericList<int> a = new GenericList<int>();
            for(int i = 0; i < 6; i++)
            {
                a.Add(Convert.ToInt32(t.NextDouble() * 10));
            }
            int sum=0;
            int Max = 0;
            int Min = 0;
            bool flag = false;
            Console.Write("本表数据分别为：");
            a.ForEach(b =>
            {
                
                Console.Write(" "+a.tem+" ");
                sum = sum + a.tem;
                if (!flag)
                {
                    Max=a.tem;
                    Min = a.tem;
                    flag = true;
                }
                else
                {
                    if (Max < a.tem)
                    {
                        Max = a.tem;
                    }
                    if (Min > a.tem)
                    {
                        Min = a.tem;
                    }
                }

            });
            Console.WriteLine("");
            Console.WriteLine("最大值为：" + Max);
            Console.WriteLine("最小值为：" + Min);
            Console.WriteLine("和值为：" + sum);



        }
    }
}
